{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f0b2f158-6037-49d8-b23d-4d5a44f8d5dd",
   "metadata": {},
   "source": [
    "# Jittered Strip Plot\n",
    "\n",
    "A scatter plot with horizontal jitter to show individual penguins' body mass grouped by species. Points are colored by species and positioned along the x-axis using slight jitter, with category labels added for clarity."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d641195-2d0c-4fb0-bd77-f91940931530",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import hvplot.pandas  # noqa\n",
    "\n",
    "np.random.seed(1)\n",
    "df = hvplot.sampledata.penguins('pandas')\n",
    "df = df[df['species'].notna()].copy()\n",
    "species_map = {'Adelie': 0, 'Chinstrap': 1, 'Gentoo': 2}\n",
    "df['x'] = df['species'].map(species_map) + np.random.uniform(-0.2, 0.2, size=len(df))\n",
    "\n",
    "df.hvplot.scatter(\n",
    "    x='x',\n",
    "    y='body_mass_g',\n",
    "    title='Simulated Jittered Strip Plot (Bokeh)',\n",
    "    xticks=[(0, 'Adelie'), (1, 'Chinstrap'), (2, 'Gentoo')],\n",
    "    by='species',\n",
    "    xlabel='Species',\n",
    "    ylabel='Body Mass (g)',\n",
    "    tools=['hover'],\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f7af0170-cb98-4596-8a67-2e67d4aaa077",
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "import numpy as np\n",
    "hvplot.extension('matplotlib')\n",
    "\n",
    "np.random.seed(1)\n",
    "df = hvplot.sampledata.penguins('pandas')\n",
    "df = df[df['species'].notna()].copy()\n",
    "species_map = {'Adelie': 0, 'Chinstrap': 1, 'Gentoo': 2}\n",
    "color_map = {'Adelie': 'blue', 'Chinstrap': 'green', 'Gentoo': 'orange'}\n",
    "\n",
    "df['x'] = df['species'].map(species_map) + np.random.uniform(-0.2, 0.2, size=len(df))\n",
    "df['color'] = df['species'].map(color_map)\n",
    "\n",
    "df.hvplot.scatter(\n",
    "    x='x',\n",
    "    y='body_mass_g',\n",
    "    by='color',\n",
    "    title='Jittered Strip Plot by Species (Matplotlib)',\n",
    "    xlabel='Species',\n",
    "    ylabel='Body Mass (g)',\n",
    "    xticks=[(0, 'Adelie'), (1, 'Chinstrap'), (2, 'Gentoo')],\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09eec6ef-dbef-48d3-8b99-520cbb29174a",
   "metadata": {},
   "source": [
    ":::{seealso}\n",
    "- [Scatter Plot reference documentation](../../ref/api/manual/hvplot.hvPlot.scatter.ipynb).\n",
    ":::"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
